package com.example.tourpal.volley;

import java.util.List;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.util.Log;

import com.android.volley.Response;
import com.android.volley.VolleyError;

public class WeatherVolleyTest {
	public void getWeatherDataTest(final Context context) {
		String url = "http://wthrcdn.etouch.cn/weather_mini?citykey=101010100";
		GsonRequest<WeatherData> gsonRequest = new GsonRequest<WeatherData>(
				url, WeatherData.class, new Response.Listener<WeatherData>() {
					@Override
					public void onResponse(WeatherData weather) {
						AlertDialog.Builder builder = new Builder(context);
						builder.setMessage(weather.toString());
						builder.create().show();
					}
				}, new Response.ErrorListener() {
					@Override
					public void onErrorResponse(VolleyError error) {
						Log.e("TAG", error.getMessage(), error);
					}
				});
		VolleySingleton.getVolleySingleton(context).addToRequestQueue(
				gsonRequest);
	}

	class WeatherData {
		String desc;
		int status;
		Data data;

		@Override
		public String toString() {
			return "WeatherData [desc=" + desc + ", status=" + status
					+ ", data=" + data + "]";
		}
	}

	class Data {
		int wendu;
		String ganmao;
		List<WeatherDetail> forecast;
		YesterdayDetail yesterday;
		int aqi;
		String city;

		@Override
		public String toString() {
			return "Data [wendu=" + wendu + ", ganmao=" + ganmao
					+ ", forecast=" + forecast + ", yesterday=" + yesterday
					+ ", aqi=" + aqi + ", city=" + city + "]";
		}
	}

	class WeatherDetail {
		String fengxiang;
		String fengli;
		String high;
		String type;
		String low;
		String date;

		@Override
		public String toString() {
			return "WeatherDetail [fengxiang=" + fengxiang + ", fengli="
					+ fengli + ", high=" + high + ", type=" + type + ", low="
					+ low + ", date=" + date + "]";
		}
	}

	class YesterdayDetail {
		String fl;
		String fx;
		String high;
		String type;
		String low;
		String date;

		@Override
		public String toString() {
			return "YesterdayDetail [fl=" + fl + ", fx=" + fx + ", high="
					+ high + ", type=" + type + ", low=" + low + ", date="
					+ date + "]";
		}

	}
}
